package me.stone.stanimeclient.util

import android.annotation.SuppressLint
import android.graphics.Color
import android.view.ViewGroup
import android.view.ViewGroup.LayoutParams
import android.widget.TextView
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import me.stone.stanimeclient.core.common.extensions.dip


class SampleTextViewHolder(textView: TextView) : RecyclerView.ViewHolder(textView)

class SampleTextAdapter : RecyclerView.Adapter<SampleTextViewHolder>() {

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): SampleTextViewHolder {
        return SampleTextViewHolder(
            TextView(parent.context).apply {
                layoutParams = LayoutParams(
                    LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT
                )
                textSize = 16f
                textAlignment = TextView.TEXT_ALIGNMENT_CENTER
                val dp8 = 8f.dip.toInt()
                setPaddingRelative(dp8, dp8, dp8, dp8)
                setTextColor(Color.WHITE)
            }
        )
    }

    override fun getItemCount(): Int {
        return 20
    }

    @SuppressLint("SetTextI18n")
    override fun onBindViewHolder(holder: SampleTextViewHolder, position: Int) {
        (holder.itemView as TextView).text = "item -> pos: $position"
    }

    override fun onAttachedToRecyclerView(recyclerView: RecyclerView) {
        recyclerView.layoutManager = LinearLayoutManager(recyclerView.context).apply {
            orientation = LinearLayoutManager.VERTICAL
        }
    }

}